﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Service.Core.Utils;
using Service.Framework.Utils;

namespace Service.Core.Filters
{
    [AttributeUsage(AttributeTargets.Method)]
    public class EncryptionResultFilter : Attribute, IAsyncResultFilter
    {
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            //// 加密返回结果
            //if (context.Result is ObjectResult objectResult)
            //{
            //    var response = JsonSerializeUtil.SerializeObject(objectResult.Value);
            //    var encryptedResponse = PlayyerUtil.Encryption(response, "123456");
            //    context.Result = new ContentResult
            //    {
            //        Content = encryptedResponse,
            //        ContentType = "text/plain",
            //        StatusCode = objectResult.StatusCode
            //    };
            //}
            await next.Invoke();
        }
    }
}
